<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link href="https://static.yimifudao.com/yimicdn/layui/css/layui.css" rel="stylesheet">
  <title>首页</title>
  <style>
    .form-wrap {
      width: 1000px;
      margin: 0 auto;
      padding-top: 40px;
    }
  </style>
</head>

<body>

  <div class="form-wrap">
    <h6>提测邮件</h6>
    <hr class="layui-bg-red">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">邮件标题</label>
        <div class="layui-input-block">
          <input type="text" name="subject" required lay-verify="required" placeholder="请输入邮件标题" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">发布项目</label>
        <div class="layui-input-block">
          <select name="rundeck" lay-verify="required">
            <option value=""></option>
            <option value="mis-m">ERP系统()</option>
            <option value="www2.1mifudao.com">pc官网</option>
            <option value="m2.1mifudao.com">移动官网</option>
            <option value="live.1mifd.com">直播课</option>
            <option value="h5.1mifd.com">app内嵌H5</option>
            <option value="static.1mifd.com">静态资源</option>
          </select>
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">需求/bug地址</label>
        <div class="layui-input-block">
          <textarea name="address" lay-verify="required" placeholder="请输入具体提测内容" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
          <textarea name="desc" lay-verify="required" placeholder="请输入具体提测内容" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>
  </div>
  <script src="https://static.yimifudao.com/yimicdn/jquery/jquery-3.3.1.min.js"></script>
  <script src="https://static.yimifudao.com/yimicdn/layui/layui.js"></script>
  <script>
    layui.use(['form', 'layer'], function () {
      var layer = layui.layer;
      var form = layui.form;

      //监听提交
      form.on('submit(formDemo)', function (data) {
        var index = layer.load(0);
        $.ajax({
          type: 'POST',
          url: '/send',
          data: data.field,
          success: function (res) {
            if (res.code === 2000) {
              layer.msg('发送成功')
              setTimeout(() => { location.reload() }, 1000)
            } else if (res.code === 2005) {
              location.href = '/login.html'
            } else {
              layer.msg('发送失败')
            }
          },
          error: function (err) {
            layer.msg('发送失败')
          },
          complete: function () {
            layer.close(index);
          }
        })
        return false;
      });
    });

  </script>
</body>

</html>